import java.io.*;
import java.util.*;
public class Main{
    int a, b;
    boolean check(int v){
        for(int i=2;i*i<=v;i++){
            if(v%i==0) return false;
        }
        return true;
    }
    int reverse(int v){
        int ans = 0;
        while(v!=0){
            ans = ans*10+v%10;
            v /= 10;
        }
        return ans;
    }
    void work(){
        Scanner reader = new Scanner(System.in);
        a = reader.nextInt();
        b = reader.nextInt();
        reader.close();
        boolean run = true;
        for(int len=1;len<=4 && run;len++){
            int beg = 1, end;
            for(int i=1;i!=len;i++)beg *= 10;
            end = beg*10;
            for(int i=beg;i!=end && run;i++){
                int ri = reverse(i);
                int v = (i/10)*end + ri;
                if(!(a<=v)) continue;
                if(!(v<=b)){
                    run = false;
                    break;
                }
                if(check(v)) System.out.println(v);
            }
            for(int i=beg;i!=end && run;i++){
                int ri = reverse(i);
                int v = i*end + ri;
                if(!(a<=v)) continue;
                if(!(v<=b)){
                    run = false;
                    break;
                }
                if(check(v)) System.out.println(v);
            }
        }
    }
    public static void main(String[]args){
        Main init = new Main();
        init.work();
    }
}